﻿using System;
using System.Collections.Generic;
using System.Linq;
using ml.Math;
using ml.Metrics;

namespace ml.Unsupervised.Linkers
{
    public class CentroidLinker : ILinker
    {
        private readonly IDistance _distanceMetric;
        public CentroidLinker(IDistance distanceMetric)
        {
            _distanceMetric = distanceMetric;
        }

        public double Distance(IEnumerable<Vector> x, IEnumerable<Vector> y)
        {
            return _distanceMetric.Compute(x.Mean(), y.Mean());
        }
    }
}